<?php

namespace addons\uniprint;

use app\common\library\Menu;
use think\Addons;
use think\Loader;

/**
 * 插件
 */
class Uniprint extends Addons
{

    /**
     * 插件安装方法
     * @return bool
     */
    public function install()
    {
        $menu = [
            0 =>
                [
                    'name' => 'uniprint',
                    'title' => 'web云打印机',
                    'icon' => 'fa fa-font-awesome',
                    'remark' => '',
                    'sublist' => [
                        0 => [
                            'name' => 'uniprint/printer',
                            'title' => '打印机管理',
                            'icon' => 'fa fa-font-awesome',
                            'remark' => '',
                            'sublist' =>
                                [
                                    [
                                        'name' => 'uniprint/printer/index',
                                        'title' => '查看',
                                        'remark' => '',
                                        'icon' => 'fa fa-circle-o',
                                        'sublist' =>
                                            [
                                            ],
                                    ],
                                    [
                                        'name' => 'uniprint/printer/add',
                                        'title' => '添加',
                                        'remark' => '',
                                        'icon' => 'fa fa-circle-o',
                                        'sublist' =>
                                            [
                                            ],
                                    ],
                                    [
                                        'name' => 'uniprint/printer/edit',
                                        'title' => '编辑',
                                        'remark' => '',
                                        'icon' => 'fa fa-circle-o',
                                        'sublist' =>
                                            [
                                            ],
                                    ],
                                    [
                                        'name' => 'uniprint/printer/delete',
                                        'title' => '删除',
                                        'remark' => '',
                                        'icon' => 'fa fa-circle-o',
                                        'sublist' =>
                                            [
                                            ],
                                    ],
                                    [
                                        'name' => 'uniprint/printer/printing',
                                        'title' => '测试打印',
                                        'remark' => '',
                                        'icon' => 'fa fa-circle-o',
                                        'sublist' =>
                                            [
                                            ],
                                    ],
                                    [
                                        'name' => 'uniprint/printer/sync',
                                        'title' => '同步状态',
                                        'remark' => '',
                                        'icon' => 'fa fa-circle-o',
                                        'sublist' =>
                                            [
                                            ],
                                    ],
                                ]
                        ],
                        1 => [
                            'name' => 'uniprint/template',
                            'title' => '打印机模板',
                            'icon' => 'fa fa-font-awesome',
                            'remark' => '更多中午云模板参考：http://www.zhongwu.co/platformPrintTemplate.html#list2'."<br>".
                                        '更多易联云模板参考：https://dev.yilianyun.net/printtemplate###'."<br>".
                                        '注意：模板中的变量必须在大括号中,只支持英文字母数字和_组合如 {I_Love_U_1314}',
                            'sublist' =>
                                [
                                    [
                                        'name' => 'uniprint/template/index',
                                        'title' => '查看',
                                        'remark' => '',
                                        'icon' => 'fa fa-circle-o',
                                        'sublist' =>
                                            [
                                            ],
                                    ],
                                    [
                                        'name' => 'uniprint/template/add',
                                        'title' => '添加',
                                        'remark' => '',
                                        'icon' => 'fa fa-circle-o',
                                        'sublist' =>
                                            [
                                            ],
                                    ],
                                    [
                                        'name' => 'uniprint/template/edit',
                                        'title' => '编辑',
                                        'remark' => '',
                                        'icon' => 'fa fa-circle-o',
                                        'sublist' =>
                                            [
                                            ],
                                    ],
                                    [
                                        'name' => 'uniprint/template/delete',
                                        'title' => '删除',
                                        'remark' => '',
                                        'icon' => 'fa fa-circle-o',
                                        'sublist' =>
                                            [
                                            ],
                                    ]
                                ]
                        ]
                    ]
                ]
        ];
        Menu::create($menu);
        return true;
    }

    /**
     * 插件卸载方法
     * @return bool
     */
    public function uninstall()
    {
        Menu::delete('uniprint');
        return true;
    }

    /**
     * 插件启用方法
     * @return bool
     */
    public function enable()
    {
        Menu::enable('uniprint');
        return true;
    }

    /**
     * 插件禁用方法
     * @return bool
     */
    public function disable()
    {
        Menu::disable('uniprint');
        return true;
    }

    /**
     * 添加命名空间
     */
    public function appInit()
    {
        //添加命名空间
        if (!class_exists('\zhongwu\protocol\RpcClient')) {
            Loader::addNamespace('zhongwu', ADDON_PATH . 'uniprint' . DS . 'library' . DS . 'zhongwu' . DS . 'printer' . DS);
        }
        if (!class_exists('\App\Config\YlyConfig')) {
            Loader::addNamespace('App', ADDON_PATH . 'uniprint' . DS . 'library' . DS . 'yly-openapi' . DS . 'yly-openapi-sdk' . DS . 'Lib' . DS);
        }
    }

}
